package com.zxx.xin.shorthand.ui.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zxx.xin.shorthand.R;
import com.zxx.xin.shorthand.database.bean.Daily;
import com.zxx.xin.shorthand.database.DatabaseHelper;
import com.zxx.xin.shorthand.ui.widget.DailyAdapter;
import java.util.List;

public class DailyListActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily_list);
        findViewById(R.id.write).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DailyWriteActivity.startPage(DailyListActivity.this, null);
            }
        });
        mRecyclerView = (RecyclerView) findViewById(R.id.daily_list_view);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
    }

    @Override
    protected void onResume() {
        super.onResume();
        List<Daily> list = DatabaseHelper.getInstance().listAllDaily();

        DailyAdapter adapter = new DailyAdapter(list, this);

        mRecyclerView.setAdapter(adapter);
        mRecyclerView.scrollToPosition(list.size() - 1);


    }
}
